// pages/order/order/order.js
var handler = require("../../../utils/function.js");
var app = getApp(),
    api = require("../../../api.js");
Page({
    /**
     * 页面的初始数据
     */
    data: {
      imgs: handler.userImg,
        img: handler.driverImg,
        order: [],
        left: 0,
        isPaid: 3,
        paid: '',
        speedFee: '',
        roadToll: '',
        otherFee: '',
        order_no: '',
        is_pay: 3,
        is_status:'未支付',
      order_url: [
        "/pages/driverOrder/orderedStatus/orderedStatus", 
        "/pages/driverOrder/orderGoing/orderGoing", 
        "/pages/driverOrder/bill/bill",
        "/pages/driverOrder/orderDetail/orderDetail"
        ],
    },
    /**
     * 生命周期函数--监听页面加载
     */
    // scrollHandler 滚动事件
    scrollHandler: function(e) {
        console.log('获取支付参数', e)
      var id = e.currentTarget.dataset.pay;
      this.setData({ isPaid: e.currentTarget.dataset.pay,is_pay: e.currentTarget.dataset.pay })
      this.getOrder();
    },
    /*upper: function(e) {
        this.setData({
            left: 0,
            isPaid: false
        });
    },
    lower: function(e) {
        console.log("lower", e)
        this.setData({
            left: 750,
            isPaid: true
        });
    },*/
    // intoPageHandler 页面跳转
    intoPageHandler: function(e) {
        handler.intoPageHandler(e.currentTarget.dataset.skip + '?order_no=' + e.currentTarget.dataset.order_no)
    },
    onLoad: function(options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        this.getOrder();
    },
    getOrder:function(){
        var that = this;
        wx.showLoading({})
        app.request({
            url: api.order.order_status,
            method: 'post',
            data: {
                is_pay: that.data.is_pay
            },
            success: function(rs) {
              wx.hideLoading()
                that.setData({
                    order: rs.data.data
                })
            }
        })
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        var that = this;
      
         wx.showNavigationBarLoading(); 
          app.request({
            url: api.order.order_status,
            method: 'post',
            data: {
                is_pay: that.data.is_pay,
            },
            success: function(rs) {
                wx.hideNavigationBarLoading()
                that.setData({
                    order: rs.data.data
                })
               
            }
        }) 
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        // 显示加载图标  
       wx.showNavigationBarLoading(); 
        var that = this;
        var p = 1;
        p = p + 1;
        const { order}=this.data;
        app.request({
            url: api.order.order_status,
            method: 'post',
            data: {
                is_pay: that.data.is_pay,
                page: p
            },
            success: function(rs) {
              order.push(rs.data.data)
                that.setData({
                  order: order
                })
                 wx.hideNavigationBarLoading()
            }
        })
      console.log(this.data.order,'2222222222222222222222222')
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {}
})